package com.zgkxzx.数据结构.栈;

import com.zgkxzx.数据结构.链表.ZLinkList;

import java.util.ArrayList;

/**
 * 创建者   zgkxzx
 * 创建日期 2018/4/30.
 * 功能描述
 */
public class LinkedStack<T> implements BaseStack<T> {
//    private ZLinkList<T> linkList;
    private ArrayList<T> list;

    private int currentIndex = -1;


    public LinkedStack(){
//        linkList = new ZLinkList<>();
        list = new ArrayList<>();
    }


    @Override
    public T pop() {
        if(currentIndex==-1)
        return null;
        int index = --currentIndex;
        T t = list.get(index);
        list.remove(t);
        return t;
    }

    @Override
    public void push(T t) {
//        linkList.add(t);
        list.add(t);
        currentIndex++;
    }

    @Override
    public T peek() {
        if(currentIndex==-1)
            return null;

        return list.get(currentIndex);
    }
}
